package com.ocom.payconfig.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.typehandler.EntityCcbPosInfo;
import com.ocom.common.response.payconfig.GetCcbNoPosDeviceListResponse;
import com.ocom.common.response.payconfig.GetCcbPosListResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 智慧生活柜台信息 Mapper 接口
 * </p>
 *
 * @author js
 * @since 2023-10-04
 */
@Mapper
public interface IDaoCcbPosInfo extends BaseMapper<EntityCcbPosInfo> {

    @Select({"<script>",
            "SELECT\n" +
                    "g.vpos_id AS vposId,\n" +
                    "g.pos_id AS posId,\n" +
                    "g.bind_merch_id AS bindMerchId,\n" +
                    "g.device_no AS deviceNo,\n" +
                    "d.point_id AS pointId,\n" +
                    "p.point_name AS pointName,\n" +
                    "p.merch_id AS merchId,\n" +
                    "m.merch_name AS bindMerchName, m.merch_name AS merchName, d.device_name AS deviceName\n" +
                    "FROM\n" +
                    "ccb_pos_info AS g\n" +
                    "LEFT JOIN xf_device_info AS d ON d.device_no = g.device_no  AND d.com_id = #{comId} " +
                    "LEFT JOIN xf_point_info AS p ON p.point_id = d.point_id  AND p.com_id = #{comId} " +
                    "LEFT JOIN xf_merchant_info AS m ON m.merch_id = p.merch_id  AND m.com_id = #{comId} " +
                    "WHERE " +
                    "g.com_id = #{comId}\n " +
                    "AND g.business_id = #{businessId}\n " +
//                    "AND g.device_no <![CDATA[<>]]> '' ORDER BY vposId " +
            "</script>"})
    List<GetCcbPosListResponse> getCcbPosList(@Param("comId") Long comId, @Param("businessId") String businessId);

    @Select({"<script>",
            "SELECT\n" +
                    "d.device_no,\n" +
                    "d.point_id AS pointId,\n" +
                    "p.point_name AS pointName,\n" +
                    "p.merch_id AS merchId,\n" +
                    "m.merch_name AS merchName,\n" +
                    "d.device_name AS deviceName,\n" +
                    "g.business_id AS businessId \n" +
                    "FROM\n" +
                    "xf_device_info AS d \n" +
                    "LEFT JOIN xf_point_info AS p ON d.point_id = p.point_id\n" +
                    "LEFT JOIN `xf_merchant_info` AS m ON m.`merch_id` = p.merch_id\n" +
                    "LEFT JOIN ccb_pos_info AS g ON g.device_no = d.device_no \n" +
                    "WHERE d.com_id = #{comId} AND ( p.merch_id = #{merchId} OR FIND_IN_SET(#{merchId}, m.merch_orgin) > 0)" +
                    "</script>"})
    List<GetCcbNoPosDeviceListResponse> getCcbNoPosDeviceListByThan(@Param("comId") Long comId, @Param("merchId") int merchId);

    @Select({"<script>",
            "SELECT\n" +
                    "d.device_no,\n" +
                    "d.point_id AS pointId,\n" +
                    "p.point_name AS pointName,\n" +
                    "p.merch_id AS merchId,\n" +
                    "m.merch_name AS merchName,\n" +
                    "d.device_name AS deviceName,\n" +
                    "g.business_id AS businessId \n" +
                    "FROM\n" +
                    "xf_device_info AS d \n" +
                    "LEFT JOIN xf_point_info AS p ON d.point_id = p.point_id\n" +
                    "LEFT JOIN `xf_merchant_info` AS m ON m.`merch_id` = p.merch_id\n" +
                    "LEFT JOIN ccb_pos_info AS g ON g.device_no = d.device_no \n" +
                    "WHERE d.com_id = #{comId} AND g.device_no IS NULL" +
                    "</script>"})
    List<GetCcbNoPosDeviceListResponse> getCcbNoPosDeviceList(@Param("comId") Long comId);
}
